<template>
  <el-form v-model="paper" size="mini" label-width="80px" label-position="left">
    <el-form-item label="分页:">
      <el-radio-group v-model="paper.pageEnabled">
        <el-radio-button :label="false">禁用</el-radio-button>
        <el-radio-button :label="true">启用</el-radio-button>
      </el-radio-group>
    </el-form-item>
    <el-form-item label="分页方式:">
      <el-radio-group v-model="paper.pagingMode">
        <el-radio-button label="fitpage">自动</el-radio-button>
        <el-radio-button label="fixrows">固定</el-radio-button>
      </el-radio-group>
    </el-form-item>
    <el-form-item label="每页行数:" v-if="paper.pagingMode==='fixrows'">
      <el-input v-model="paper.fixRows"  oninput="value=value.replace(/[^\d]/g,'')" style="width: 136px;" size="mini" />
    </el-form-item>
  </el-form>
</template>

<script>

export default {
  name: 'PaginationSetting',
  props: {
    context: {
      type: Object,
      required: true
    }
  },
  data: function() {
    return {
      paper: {
        pageEnabled: false,
        pagingMode: 'fitpage',
        fixRows: 10
      }
    }
  },
  watch: {
    context: function(val) {
      this.init()
    }
  },
  mounted: function() {
    this.init()
  },
  methods: {
    init() {
      const paper = this.context.reportDef.paper
      if(paper.pageEnabled === undefined) {
        paper.pageEnabled = false
      }
      if(paper.pagingMode === undefined) {
        paper.pagingMode = 'fitpage'
      }
      if(paper.fixRows === undefined) {
        paper.fixRows = 10
      }
      this.paper = paper
    }
  }
}
</script>

<style>
</style>
